import {createSlice} from '@reduxjs/toolkit'
import dayjs from 'dayjs'
 const ticketSlice=createSlice({
    name:'ticket',
    initialState:{
        start:'上海',//出发地
        end:'上海',//目的地
        date:dayjs().format('YYYY-MM-DD'),//时间
        isSpeed:false,//是否只看高铁
        sousuoheji:[]
    },
    reducers:{
        outdataHuan(state){
            const temp=state.start
            state.start=state.end
            state.end=temp
        },
        outdataKai(state,action){
            console.log(action);
            state.isSpeed=action.payload
        },
        ondatashi(state,action){
            state.date=dayjs(action.payload).format('YYYY-MM-DD')
        },
        setCity(state,action){
            state[action.payload.porName]=action.payload.city
        },
        qingkong(state){
            state.sousuoheji=[]
        },
        // 添加搜索历史
        sousuolishi(state,action){
            state.sousuoheji.unshift(action.payload)
            const set=new Set(state.sousuoheji)
            
            state.sousuoheji=Array.from(set)
            console.log('aaaaaa'+state.sousuoheji)
        }
    },
  
})
export default ticketSlice.reducer
export const {outdataHuan,outdataKai,ondatashi,setCity,sousuolishi,qingkong}=ticketSlice.actions